import { USERINFO_KEY } from '@/utils/constants'
import { useRouter } from 'vue-router'

export function getUserInfo() {
  let userInfo = localStorage.getItem(USERINFO_KEY)
  if (userInfo) {
    userInfo = JSON.parse(userInfo)
  }
  if (!userInfo) {
    const router = useRouter()
    router.push({ name: 'login' })
    return {}
  }
  return userInfo
}
